﻿<?php
require_once('./load.php');
$smarty->assign("s1","login");

if(LOGGED == false){
	if(isset($_POST['username']) && isset($_POST['userpass'])){
		if(count($sql->QueryGetFetch("SELECT * FROM `uzytkownicy` WHERE `login`='".$_POST['username']."' AND `haslo`='".md5($_POST['userpass'])."' AND `prawa`='3'"))){ //  
			$ck = md5(time());
			$sql->query("UPDATE `uzytkownicy` SET `hash_code` = '".$ck."' WHERE `login`='".$_POST['username']."'");
			setcookie("admin_cookie_user", $_POST['username']);
			setcookie("admin_cookie_hashcode", $ck);
			
			//header('Location: ./index.php');
			//echo 'SELECT * FROM "Uzytkownicy" WHERE "user_name"=\''.$_POST['username'].'\' AND "USER_COOKIE_HASH"=\''.($ck).'\'';
			header('Location: ./index.php');
		}
	}
}else{
	//header('Location: ./index.php');
}
$smarty->display('templates/index.tpl');
?>